
import java.util.List;
import java.util.Scanner;

import xyh.ContributionSystem.Projects.*;
import xyh.ContributionSystem.ProjectMember.*;
import xyh.ContributionSystem.ProjectContribution.*;
import xyh.ContributionSystem.ConSysByUser;
import ls.dao.CourseDAO;
import ls.dao.StudentDAO;
import ls.entity.Course;
import ls.entity.Student;
import ls.impl.StudentDAOImpl;//mark
import ls.test.*;
import zry.Operate.Search;
import zry.User.AdministratorUser;
import zry.User.StudentUser;
import zry.User.TeacherUser;
import lx.*;
import zrz.DAOFactory;
import zrz.People;

public class Main {
    private static ProjectDAO projectDAO;
    private static ProjectMemberDAO projectMemberDAO;
    private static ProjectContributionDAO projectContributionDAO;
    public double ExpenditureRequirement = 6;

    public static void main(String[] args) {
        String userId = null;
        while (true) {
            System.out.println("欢迎使用研究生培养系统，请选择您的身份：\n1.研究生\n2.授课教师\n3.学科负责人\n4.导师\n5.研究生培养管理员\n6.退出系统");
            Scanner scanner = new Scanner(System.in);
            int op = scanner.nextInt();
            if (op == 6) break;
            if (op != 1 && op != 2 && op != 3 && op != 4 && op != 5) {
                System.out.println("身份选择错误，请重新选择");
                continue;
            }
            System.out.println("请输入用户id：");
            userId = scanner.next();
            System.out.println("请输入密码：");
            String passWord = scanner.next();
            //login
            People login = DAOFactory.getInstance().getPeopleDAO().getPeopleById(Integer.parseInt(userId));

            if(login == null)
            {
                System.out.println("该用户id暂未保存到系统中，请联系研究生培养管理员添加");
                continue;
            }
            else if (!login.getP_password().equals(passWord)) {
                System.out.println("用户id或密码错误");
                continue;
            }
            String identity = login.getP_identity();
            if (identity.equals("研究生") && op == 1) {
                while (true) {
                    System.out.println("请选择您要执行的功能");
                    System.out.println("1.提交学术交流情况审核表");
                    System.out.println("2.助教相关工作");
                    System.out.println("3.成果认定工作");
                    System.out.println("4.提交项目贡献");
                    System.out.println("5.查看学术交流活动审核情况");
                    System.out.println("6.退出登录");
                    int id = login.getP_id();
                    String student_id = Integer.toString(id);
                    op = scanner.nextInt();
                    if (op == 2) {
                        System.out.println("学号为" + student_id + "的研究生您好！");
                        StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
                        Student student = studentDAO.getStudent(student_id);
                        if (student == null) {
                            CreateStudent createStudent = new CreateStudent();
                            createStudent.createStudent(student_id);// 新增研究生
                        } else {
                            ChooseCourse chooseCourse = new ChooseCourse(); //进行助教填报、评定表申请等
                            chooseCourse.chooseCourse(student_id);
                        }
                    } else if (op == 3) {
                        StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
                        Student student = studentDAO.getStudent(userId);//根据id获取student
                        new StudentUser().StudentAchievementSystem(userId, student.getStudent_education());
                    } else if (op == 4) {
                        ConSysByUser conSysByUser = new ConSysByUser();
                        conSysByUser.submitContribution(Integer.parseInt(student_id));
                    } else if (op == 5) {
                        new Controller().studentQuery(student_id);
                    } else if (op == 6) {
                        break;
                    } else if (op == 1) {
                        new Controller().studentAdd(login.getP_name());
                    }
                }

            } else if (identity.equals("授课教师") && op == 2) {
                while (true) {
                    System.out.println("请选择您要执行的功能");
                    System.out.println("1.课程信息录入");
                    System.out.println("2.助教选择");
                    System.out.println("3.审核助教工作评定表");
                    System.out.println("4.查看已录入的我的全部课程");
                    System.out.println("5.查看我已处理的全部评定表");
                    System.out.println("6.退出登录");
                    Scanner scanner2 = new Scanner(System.in);
                    int id = login.getP_id();
                    String teacher_id = Integer.toString(id);
                    int choose = scanner2.nextInt();
                    if (choose == 1) {
                        CreateCourse createCourse = new CreateCourse();//课程信息录入
                        createCourse.create(teacher_id);
                    } else if (choose == 2) {
                        ChooseStudent cs = new ChooseStudent(); // 选助教
                        cs.chooseStudent(teacher_id);
                    } else if (choose == 3) {
                        TeacherEvaluate te = new TeacherEvaluate();//审核评定表
                        te.teacherEvaluate(teacher_id);
                    } else if (choose == 4) {
                        ChooseStudent chooseStudent = new ChooseStudent();
                        chooseStudent.showCourse(teacher_id); //查看自己录入过的课程
                    } else if (choose == 5) {
                        TeacherEvaluate te = new TeacherEvaluate();
                        te.getMyEvaluate(teacher_id); // 查看自己审核过的评定表
                    } else if (choose == 6) {
                        break;
                    }
                }
            } else if (identity.equals("学科负责人") && op == 3) {
                while (true) {
                    System.out.println("1.查看导师信息与研究生培养情况");
                    System.out.println("2.查看所有项目信息");
                    System.out.println("3.修改项目经费");
                    System.out.println("4.审核学生的学术交流情况");
                    System.out.println("5.退出登录");
                    op = scanner.nextInt();
                    if (op == 1) {
                        //todo
                    }
                    else if (op == 2) {
                        ConSysByUser conSysByUser = new ConSysByUser();
                        conSysByUser.printAllProjects();
                    } else if (op == 3) {
                        ConSysByUser conSysByUser = new ConSysByUser();
                        conSysByUser.updateProject();
                    } else if (op == 4) {
                        new Controller().manApproval();
                    } else if (op == 5) {
                        break;
                    }
                }

            } else if (identity.equals("导师") && op == 4) {
                while (true) {
                    System.out.println("1.展示学生项目贡献信息");
                    System.out.println("2.修改学生项目贡献信息");
                    System.out.println("3.审核学生的学术交流情况");
                    System.out.println("4.认证学生项目经历");
                    System.out.println("5.成果认定工作");
                    System.out.println("6.退出登录");
                    op = scanner.nextInt();
                    if (op == 1) {
                        ConSysByUser conSysByUser = new ConSysByUser();
                        conSysByUser.showContributionByTeacherId(Integer.parseInt(userId));
                    }
                    else if (op == 2) {
                        ConSysByUser conSysByUser = new ConSysByUser();
                        conSysByUser.updateContributionByTeacherId(Integer.parseInt(userId));
                    }
                    else if (op == 3) {
                        new Controller().teacherApproval(login.getP_name());
                    }
                    else if (op == 4) {
                        ConSysByUser conSysByUser = new ConSysByUser();
                        conSysByUser.approveStudent(Integer.parseInt(userId));
                    } else if (op == 5) {
                        new TeacherUser().TeacherAchievementSystem(userId);
                    } else if (op == 6) {
                        break;
                    }
                }

            } else if (identity.equals("研究生培养管理员") && op == 5) {
                while (true) {
                    System.out.println("1.管理用户信息");
                    System.out.println("2.管理课程信息");
                    System.out.println("3.审核毕业信息并导出");
                    System.out.println("4.用户身份建立");
                    System.out.println("5.录入项目信息");
                    System.out.println("6.查看所有项目信息");
                    System.out.println("7.成果认定工作");
                    System.out.println("8.退出登录");
                    op = scanner.nextInt();
                    if (op == 1) {
                        System.out.println("下面是用户信息:");
                        List<People> allPeople = DAOFactory.getInstance().getPeopleDAO().getAllPeople();
                        for(People p : allPeople){
                            System.out.println(p);
                        }
                        System.out.println("请选择您要执行的具体操作：");
                        System.out.println("1.添加用户信息");
                        System.out.println("2.修改用户信息");
                        System.out.println("3.删除用户信息");
                        int a = scanner.nextInt();
                        if(a == 1){
                            People people = new People();
                            System.out.println("请输入要添加的用户名:");
                            String s = scanner.next();
                            people.setP_name(s);
                            System.out.println("请输入要添加的用户密码:");
                            s = scanner.next();
                            people.setP_password(s);
                            System.out.println("请输入要添加的用户身份:");
                            s = scanner.next();
                            people.setP_identity(s);
                            if (people.getP_identity().equals("研究生")){
                                Student stu = new Student();
                                stu.setStudent_id(String.valueOf(people.getP_id()));
                                stu.setStudent_name(people.getP_name());
                                stu.setStudent_pwd(people.getP_password());
                                DAOFactory.getInstance().getStudentDAO().addStudent(stu);
                            }
                            DAOFactory.getInstance().getPeopleDAO().addPeople(people);
                        }
                        else if (a == 2){
                            System.out.println("请输入要修改的用户id:");
                            String s1 = scanner.next();
                            System.out.println("请输入要修改的用户密码:");
                            String s2 = scanner.next();
                            DAOFactory.getInstance().getPeopleDAO().updatePeople(Integer.parseInt(s1), s2);

                        }
                        else if (a == 3){
                            System.out.println("请输入要删除的用户id:");
                            String s = scanner.next();
                            DAOFactory.getInstance().getPeopleDAO().delPeople(Integer.parseInt(s));
                        }
                        }
                    else if (op == 2) {
                        System.out.println("请选择您要执行的具体操作：");
                        System.out.println("1.查看全部已录入课程");
                        System.out.println("2.修改课程信息");
                        System.out.println("3.删除课程信息");
                        System.out.println("4.返回");
                        int a = scanner.nextInt();
                        CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
                        List<Course> courseList = courseDAO.getAllCourse();
                        ChooseStudent cs = new ChooseStudent();
                        if (a == 1) {
                            cs.course(courseList); // 输出全部课程
                        } else if (a == 2) {
                            System.out.println("请输入要修改课程的课程名：");
                            String courseName = scanner.next();
                            boolean b = cs.isCourse(courseList, courseName);
                            if (b) {
                                String course_property = "null";
                                String course_student = "null";
                                String course_hour = "null";
                                String number = "";
                                System.out.print("新的课程性质：");
                                course_property = scanner.next();
                                System.out.print("新的授课对象：（本科生/研究生）");
                                course_student = scanner.next();
                                System.out.print("新的学时：");
                                course_hour = scanner.next();
                                System.out.print("新的选课人数：");
                                number = scanner.next();
                                Course course = new Course();
                                course.setCourse_name(courseName);
                                course.setCourse_property(course_property);
                                course.setCourse_student(course_student);
                                course.setCourse_hour(course_hour);
                                course.setNumber(number);
                                courseDAO.updateCourse2(course);
                                System.out.print("修改成功！");
                            } else {
                                System.out.println("课程表中暂无此课程！");
                            }

                        } else if (a == 3) {
                            System.out.println("请输入要删除课程的课程名：");
                            String courseName = scanner.next();
                            boolean b = cs.isCourse(courseList, courseName);
                            if (b) {
                                courseDAO.deleteCourse(courseName);
                                System.out.println("删除课程成功！");
                            } else {
                                System.out.print("课程表中暂无此课程！");
                            }
                        } else if (a == 4) {
                            return;
                        }
                    }
                    else if (op == 3) {
                        //todo
                        //找到申请用户
                        //所有人都要用
                        //助教结果
                        //项目次数
                        //todo
                        //成果
                        Search search = new Search();
                        //search.searchAllMyAchievement(id);
                    }
                    else if (op == 4) {
                        System.out.println("请选择新建用户身份：");
                        System.out.println("1.学科负责人");
                        System.out.println("2.授课教师");
                        System.out.println("3.导师");
                        op = scanner.nextInt();
                        People people = new People();
                        if (op == 1) people.setP_identity("学科负责人");
                        else if (op == 2) people.setP_identity("授课教师");
                        else if (op == 3) people.setP_identity("导师");
                        String newName = scanner.next();
                        String newPass = scanner.next();
                        people.setP_name(newName);
                        people.setP_password(newPass);
                    }
                    else if (op == 5) {
                        //负责定期录入导师的项目情况
                        ConSysByUser conSysByUser = new ConSysByUser();
                        conSysByUser.addProjectSys(Integer.parseInt(userId));
                    }
                    else if (op == 6) {
                        //查看所有项目信息
                        ConSysByUser conSysByUser = new ConSysByUser();
                        conSysByUser.printAllProjects();
                    }
                    else if (op == 7) {
                        new AdministratorUser().AdministratorAchievementSystem();
                    }
                    else if (op == 8) {
                        break;
                    }
                }

            } else {
                System.out.println("用户类型选择不符，请重新检查输入");
            }
        }
    }
}